package com.ruoyi.finances.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.finances.domain.TbCredentials;
import com.ruoyi.finances.service.ITbCredentialsService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 凭证Controller
 * 
 * @author 阿飞
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/credential")
public class TbCredentialsController extends BaseController
{
    @Autowired
    private ITbCredentialsService tbCredentialsService;

    /**
     * 查询凭证列表
     */
    @RequiresPermissions("finances:credential:list")
    @GetMapping("/list")
    public TableDataInfo list(TbCredentials tbCredentials)
    {
        startPage();
        List<TbCredentials> list = tbCredentialsService.selectTbCredentialsList(tbCredentials);
        return getDataTable(list);
    }

    /**
     * 导出凭证列表
     */
    @RequiresPermissions("finances:credential:export")
    @Log(title = "凭证", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCredentials tbCredentials)
    {
        List<TbCredentials> list = tbCredentialsService.selectTbCredentialsList(tbCredentials);
        ExcelUtil<TbCredentials> util = new ExcelUtil<TbCredentials>(TbCredentials.class);
        util.exportExcel(response, list, "凭证数据");
    }

    /**
     * 获取凭证详细信息
     */
    @RequiresPermissions("finances:credential:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCredentialsService.selectTbCredentialsById(id));
    }

    /**
     * 新增凭证
     */
    @RequiresPermissions("finances:credential:add")
    @Log(title = "凭证", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCredentials tbCredentials)
    {
        return toAjax(tbCredentialsService.insertTbCredentials(tbCredentials));
    }

    /**
     * 修改凭证
     */
    @RequiresPermissions("finances:credential:edit")
    @Log(title = "凭证", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCredentials tbCredentials)
    {
        return toAjax(tbCredentialsService.updateTbCredentials(tbCredentials));
    }

    /**
     * 删除凭证
     */
    @RequiresPermissions("finances:credential:remove")
    @Log(title = "凭证", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCredentialsService.deleteTbCredentialsByIds(ids));
    }
}
